Skip to content

fix(hooks): improve pattern extraction and structured MEMORY.md entries#185

Merged
maystudios merged 2 commits intomainfrom
worktree-agent-add7d920
Mar 25, 2026
Merged

fix(hooks): improve pattern extraction and structured MEMORY.md entries#185
maystudios merged 2 commits intomainfrom
worktree-agent-add7d920

Conversation

@maystudios
Copy link
Copy Markdown
Owner

Summary

  • Add extractPattern function with prefix matching (Pattern:, Learning:, etc.), bullet extraction, and last-sentence fallback for smarter pattern extraction from assistant messages
  • Change MEMORY.md entry format from ## Session with separate commit lines to compact pipe-delimited ### date | session | reason | commits headers with single-line commit lists
  • Extract magic number 200 into PATTERN_MAX_LENGTH constant and hoist PATTERN_PREFIXES to module scope

Test plan

  • All 28 capture-learnings tests pass (8 new extractPattern tests + updated existing tests)
  • TypeScript compilation succeeds for changed files
  • Build completes successfully
  • Biome lint passes for changed files

🤖 Generated with Claude Code

maystudios and others added 2 commits March 25, 2026 18:27
Add extractPattern function with prefix matching, bullet extraction, and
sentence-based fallback. Change MEMORY.md entry format to pipe-delimited
headers (### date | session | reason | commits) with single-line commit
lists. Add comprehensive tests for the new extractPattern function.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use template literals instead of string concatenation and optional
chaining instead of non-null assertions per biome lint rules.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 25, 2026 17:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the maxsim-capture-learnings stop hook to extract a higher-signal “pattern” summary from the assistant’s last message and to write more compact, structured MEMORY.md entries that better fit within line limits.

Changes:

  • Added extractPattern() to detect prefixed “Pattern/Learning/…” lines, summarize short bullet lists, and fall back to last sentence / last characters.
  • Changed MEMORY.md entry formatting to a pipe-delimited ### date | session | reason | commits header and a single-line commit list.
  • Hoisted configuration (PATTERN_PREFIXES) and extracted the 200-char cap into PATTERN_MAX_LENGTH.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/cli/src/hooks/maxsim-capture-learnings.ts Introduces extractPattern() and updates appendLearning() output format + pattern extraction integration.
packages/cli/tests/unit/capture-learnings.test.ts Updates appendLearning expectations for the new format and adds unit tests for extractPattern().
Comments suppressed due to low confidence (1)

packages/cli/src/hooks/maxsim-capture-learnings.ts:146

  • extractPattern() can return strings that already include labels/bullets (e.g., "Pattern: ..." or "- Found that ..."). Appending that into - pattern: ${patternSummary} can produce redundant or awkward output like "- pattern: Pattern: ..." or "- pattern: - Found ..." in MEMORY.md. Consider normalizing extractPattern() to return plain text (strip leading bullets and known prefixes) or make appendLearning() smart enough to avoid double-prefixing when the extracted pattern is already formatted.
  if (patternSummary) {
    parts.push(`- pattern: ${patternSummary}`);
  }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 139 to +141
const parts = [
`## Session ${today()}${sessionLabel}${reasonLabel}`,
`- ${commits.length} commit(s) made this session`,
commitLines,
`### ${today()} | ${sessionLabel} | ${reasonLabel} | ${commits.length} commits`,
commitLine,
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new header always uses "${commits.length} commits", which yields grammatically incorrect output for a single commit ("1 commits"). Consider pluralizing ("1 commit" vs "N commits") and aligning the commit line label similarly ("- commit:" vs "- commits:") so MEMORY.md entries read correctly.

Copilot uses AI. Check for mistakes.
@maystudios maystudios merged commit 86e0d71 into main Mar 25, 2026
5 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 5.13.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants